package com.lib.model.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.lib.model.dto.BookDto;
import com.lib.model.dto.BookLostDto;
import com.lib.model.dto.ClassfycodeDto;
import com.lib.model.dto.DetailcodeDto;
import com.lib.model.dto.LendingDto;
import com.lib.model.dto.StatecodeDto;
import com.lib.paging.ResultLists;

public class BookLostDao extends SqlMapClientDaoSupport implements IBookLostDao {

	@Override
	public int getAllLostBookCount() {
		int count = 0;

		count = (Integer) getSqlMapClientTemplate().queryForObject(
				"LostMap.getAllLostBookCount");

		return count;
	}

	@Override
	public ArrayList<BookLostDto> getAllLostBook(int startn, int endn) {
		ArrayList<BookLostDto> list = null;
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("startpage", startn);
		map.put("endpage", endn);

		list = (ArrayList<BookLostDto>) getSqlMapClientTemplate().queryForList(
				"LostMap.getAllLostBook", map);

		return list;
	}

	@Override
	public boolean setReparacheck(BookLostDto lostdto) {
		boolean flag = false;
		try {
			this.getSqlMapClientTemplate().update("LostMap.setReparacheck",
					lostdto);
			flag = true;
		} catch (Exception e) {

		}
		return flag;
	}

	@Override
	public ArrayList<BookLostDto> searchAllLostBook(int startPage,
			int startBlock, String searchType, String searchValue) {

		ArrayList<BookLostDto> list = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("startpage", startPage);
		map.put("endpage", startBlock);
		map.put("searchType", searchType);
		map.put("searchValue", searchValue);

		list = (ArrayList<BookLostDto>) getSqlMapClientTemplate().queryForList(
				"LostMap.searchAllLostBook", map);

		return list;
	}

	@Override
	public int getSearchAllLostBookCount(String searchType, String searchValue) {
		int count = 0;

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("searchType", searchType);
		map.put("searchValue", searchValue);

		count = (Integer) getSqlMapClientTemplate().queryForObject(
				"LostMap.getSearchAllLostBookCount", map);

		return count;
	}

	@Override
	public int getAllMemLostBookCount() {
		int count = 0;

		count = (Integer) getSqlMapClientTemplate().queryForObject(
				"LostMap.getAllMemLostBookCount");

		return count;
	}

	@Override
	public ArrayList<BookLostDto> getAllMemLostBook(int startn, int endn) {
		ArrayList<BookLostDto> list = null;
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("startpage", startn);
		map.put("endpage", endn);

		list = (ArrayList<BookLostDto>) getSqlMapClientTemplate().queryForList(
				"LostMap.getAllMemLostBook", map);

		return list;
	}

	@Override
	public boolean insertMemLostBooks(ArrayList<BookLostDto> lostbooks) {
		boolean flag = false;
		try {
			for (int i = 0; i < lostbooks.size(); i++) {
				this.getSqlMapClientTemplate().insert(
						"LostMap.insertMemLostBook", lostbooks.get(i));
			}

			flag = true;
		} catch (Exception e) {

		}
		return flag;
	}

	@Override
	public boolean deleteLostBooks(String[] ids) {
		boolean flag = false;
		try {
			for (int i = 0; i < ids.length; i++) {
				this.getSqlMapClientTemplate().delete("LostMap.deleteLostBook",
						ids[i]);
			}
			flag = true;
		} catch (Exception e) {

		}
		return flag;
	}

}
